﻿using Architecture.API.Application.Command.MenuCommand;
using Architecture.Domain.Dto.MenuDto;
using Architecture.Domain.Service.MenuServices;
using MediatR;

namespace Architecture.API.Application.CommandHandlers.MenuCommandHandler
{
    /// <summary>
    /// 菜单动态显示创建命令处理器
    /// </summary>
    public class GetMenuCommandHandler : IRequestHandler<GetMenuCommand, List<MenuDto>>
    {
        /// <summary>
        /// 菜单服务
        /// </summary>
        private readonly IMenuService _menuService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="menuService">菜单服务</param>
        public GetMenuCommandHandler(IMenuService menuService)
        {
            _menuService = menuService;
        }

        /// <summary>
        /// 菜单动态显示
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>返回菜单动态信息</returns>
        public async Task<List<MenuDto>> Handle(GetMenuCommand request, CancellationToken cancellationToken)
        {
            return await _menuService.GetMenu(request.userId);
        }
    }
}
